/*
 * @Author: wuheng wuheng@szhbzc.com
 * @Date: 2025-02-20 10:10:01
 * @LastEditors: wuheng wuheng@szhbzc.com
 * @LastEditTime: 2025-02-20 10:10:13
 * @FilePath: \web-appc:\Users\wuheng\Desktop\WugangNew\src\utils\loading.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ElLoading } from 'element-plus';

let loadingInstance = null as any;

// 显示加载效果的函数，支持传入自定义配置
const showLoading = (options = {}) => {
  const defaultOptions = {
    lock: true,
    text: '加载中...',
    background: 'rgba(0, 0, 0, 0.7)'
  };
  // 合并默认配置和用户传入的配置
  const finalOptions = { ...defaultOptions, ...options };
  loadingInstance = ElLoading.service(finalOptions);
};

// 隐藏加载效果的函数
const hideLoading = () => {
  if (loadingInstance) {
    loadingInstance.close();
    loadingInstance = null;
  }
};

export { showLoading, hideLoading };